package com.ry.demo.concurrent.demo.lock;


import java.util.concurrent.CountDownLatch;

public class CountDownLatchDemo {


    public static void main(String[] args) throws InterruptedException {

        CountDownLatch countDownLatch = new CountDownLatch(2);

        new Thread(()->{
            System.out.println("线程1");
            countDownLatch.countDown();
            System.out.println("线程1结束");
        }).start();

        new Thread(()->{
            System.out.println("线程2");
            countDownLatch.countDown();
            System.out.println("线程2结束");
        }).start();


        new Thread(()->{
            try {
                countDownLatch.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("main1线程结束");
        }).start();

        new Thread(()->{
            try {
                countDownLatch.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("main2线程结束");
        }).start();


        while (true){

        }

    }

}
